summaryrefslogtreecommitdiff
path: root/app/[lng]/evcp/(evcp)/avl/[id]/page.tsx
blob: 52ee7b7fb2c8fc2574a0feed07b0518eadd7610a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import * as React from "react"
import { type SearchParams } from "@/types/table"
import { notFound } from "next/navigation"

import { getValidFilters } from "@/lib/data-table"
import { DataTableSkeleton } from "@/components/data-table/data-table-skeleton"
import { getAvlLists, getAvlDetail } from "@/lib/avl/service"
import { avlDetailSearchParamsCache } from "@/lib/avl/validations"
import { AvlDetailTable } from "@/lib/avl/table/avl-detail-table"
import { getAvlListById } from "@/lib/avl/service"

interface AvlDetailPageProps {
  params: Promise<{ id: string }>
  searchParams: Promise<SearchParams>
}

export default async function AvlDetailPage(props: AvlDetailPageProps) {
  const { id } = await props.params
  const searchParams = await props.searchParams
  const search = avlDetailSearchParamsCache.parse(searchParams)

  const validFilters = getValidFilters(search.filters)

  // ID 검증
  const numericId = Number(id)
  if (isNaN(numericId) || numericId <= 0) {
    notFound()
  }

  // AVL 리스트 정보 조회
  const avlListInfo = await getAvlListById(numericId)
  if (!avlListInfo) {
    notFound()
  }

  const promises = Promise.all([
    getAvlDetail({
      ...search,
      filters: validFilters,
      avlListId: numericId,
    }),
  ])

  return (
    <div className="h-screen flex flex-col">
      {/* 메인 콘텐츠 영역 */}
      <div className="flex-1 overflow-hidden">
        <div className="h-full p-4 md:p-6">
          <React.Suspense
            fallback={
              <DataTableSkeleton
                columnCount={20}
                searchableColumnCount={1}
                filterableColumnCount={5}
                cellWidths={[
                  "50px", "60px", "120px", "120px", "150px", "130px", "130px",
                  "140px", "140px", "100px", "100px", "100px", "100px", "120px",
                  "140px", "150px", "80px", "100px", "80px", "140px", "120px",
                  "160px", "100px", "120px", "120px", "130px", "120px", "130px", "200px"
                ]}
                shrinkZero
              />
            }
          >
            <AvlDetailTableWrapper
              promises={promises}
              avlListId={Number(id)}
              avlListInfo={avlListInfo}
            />
          </React.Suspense>
        </div>
      </div>
    </div>
  )
}

// 실제 데이터를 받아서 AvlDetailTable에 전달하는 컴포넌트
function AvlDetailTableWrapper({
  promises,
  avlListId,
  avlListInfo
}: {
  promises: Promise<any>
  avlListId: number
  avlListInfo: any
}) {
  const [{ data, pageCount }] = React.use(promises)

  // AVL 타입 결정
  const avlType = avlListInfo.isTemplate ? '선종별표준AVL' : '프로젝트AVL'

  // 선주명 추출 (프로젝트 정보에서)
  const shipOwnerName = avlListInfo.shipOwnerName || undefined

  return (
    <AvlDetailTable
      data={data}
      pageCount={pageCount}
      avlListId={avlListId}
      avlType={avlType}
      projectCode={avlListInfo.projectCode}
      shipOwnerName={shipOwnerName}
      businessType={avlListInfo.constructionSector || '조선'}
    />
  )
}